<?php
//
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'main';
if($_RQ['op']=='main'){
	//注册会员
	$return['ischecklogin']=cfc('core')->checklogin('','',true);
	$item=model('core/member')->detail($_SESSION['uid'],array('id','credit1','credit2','credit3','credit4','credit5','credit6','mobile','avatar','nickname'));
	$item['id']=$_SESSION['uid'];
	$return['setting']=$return['pluginset'];
	$return['type']=0;
	$return['item']=$item;
	$credit_types=credit_types();
	$credit_types2=array();
	foreach($credit_types as $key=>$value){
		$fee=$item['credit'.$key];
		$credit_types2[$key]=array(
			'id'=>$key,
			'title'=>$value,
			'fee'=>$fee
		);
	}
	$return['credit_types']=$credit_types2;
	$this->setting['jifen_rate']=$this->setting['jifen_rate']?:1;
	$return['jifen_rate']=round($this->setting['jifen_rate'],2)*1;
	set_html('title','会员中心');
	exi($return);
}
if($_RQ['op']=='recharge'){
	$post=get_postdata();
	if(intval($post['jifen'])<=0){
		exi('请先设置额度！并且为整数！','error');
	}
	$this->setting['jifen_rate']=$this->setting['jifen_rate']?:1;
	$jifen_rate=round($this->setting['jifen_rate'],2)*1;
	$fee=$post['jifen']/$jifen_rate;
	$data=array(
		'uniacid'=>$_SESSION['uniacid'],
		'mid'=>$_SESSION['uid'],
		'couponid'=>intval($post['couponid']),
		'fee'=>$fee,
		'credit'=>$post['jifen'],
		'type'=>$post['type'],
		'createtime'=>TIMESTAMP
	);
	pdo_insert('core_recharge',$data);
	$id=pdo_insertid();
	$params=array(
		'action'=>'recharge',
		'id'=>$id,
		'fee'=>$fee,
		'title'=>'金币充值',
		'plugin'=>'core',
		//'pay_type'=>'wechat',
		'no_type'=>array('hdfk'),
		'back_url'=>'core/member.xunibi/pay_result',
		'success_url'=>'core/member.xunibi//type='.$post['type'],
		'error_url'=>'core/member.xunibi//type='.$post['type'],
	);
	if($_SESSION['container']=='aliapp' && $_SESSION['aliappopenid']){
		$params['pay_type']='alipay';
	}
	$pay_id=cfc('pay')->create_pay_order($params);
	exi($pay_id);
}
?>